#include "Gateway.h"
#include "WString.h"
#include "IEthernet.h"

#include "mock/ArduinoMock.h"
#include "mock/EthernetMock.h"
#include "mock/MessageRouterMock.h"
#include "mock/LoggerMock.h"



class GatewayTest : public ::testing::Test {
public:
	GatewayTest() : g(arduino, r, e, logger) {}
protected:
	MessageRouterMock r;
	EthernetMock e;
	ArduinoMock arduino;
	Gateway g;
	LoggerMock logger;
};

TEST_F(GatewayTest, isInfrastructure){
	ASSERT_TRUE(g.isInfrastructure());
}

TEST_F(GatewayTest, broadcastToEthernet){
	
	EXPECT_CALL(e, sendMessage(String("Ala ma kota"))).Times(1);
	g.onMessage("Ala ma kota");
}

TEST_F(GatewayTest, receiveFromEthernetWhenMessageArrived){
	
	EXPECT_CALL(e, isMessageReady()).
		Times(1).
		WillOnce(Return(true));
	EXPECT_CALL(e, isInitialized()).
		Times(1).
		WillOnce(Return(true));
	
	EXPECT_CALL(e, getMessage()).
		Times(1).
		WillOnce(Return("Ala ma kota"));
	
	EXPECT_CALL(r, postMessage(_, String("Ala ma kota")))
		.Times(1);

	g.tick(10);
}

TEST_F(GatewayTest, receiveFromEthernetWhenNoMessage){
	
	EXPECT_CALL(e, isMessageReady()).
		Times(1).
		WillOnce(Return(false));
	EXPECT_CALL(e, isInitialized()).
		Times(1).
		WillOnce(Return(true));
	
	g.tick(10);
}
TEST_F(GatewayTest, etherNotInitialized){
	
	EXPECT_CALL(e, isInitialized()).
		Times(1).
		WillOnce(Return(false));
	
	g.tick(10);
}
